#include "usr_inc.h"

/**
 * @brief 初始化所有CAN控制器
 */
void ALL_BSP_CAN_Init(void)
{
    FDCAN_FilterTypeDef canFliter = {0};

    canFliter.IdType = FDCAN_STANDARD_ID;
    canFliter.FilterIndex = 0;
    canFliter.FilterType = FDCAN_FILTER_MASK;
    canFliter.FilterConfig = FDCAN_FILTER_TO_RXFIFO0;
    canFliter.FilterID1 = 0x0000;
    canFliter.FilterID2 = 0x0000;
    HAL_FDCAN_ConfigFilter(&hfdcan1, &canFliter);
    HAL_FDCAN_ConfigFilter(&hfdcan2, &canFliter);

    /* 开启FDCAN外设 */
    HAL_FDCAN_Start(&hfdcan1); // FDCAN外设的开启需要在中断的使能之前
    HAL_FDCAN_Start(&hfdcan2);

    /* 使能中断 */
    HAL_FDCAN_ActivateNotification(&hfdcan1, FDCAN_IT_RX_FIFO0_NEW_MESSAGE, 0);
    HAL_FDCAN_ActivateNotification(&hfdcan2, FDCAN_IT_RX_FIFO0_NEW_MESSAGE, 0);

    /* 过滤所有不匹配帧 */
    HAL_FDCAN_ConfigGlobalFilter(&hfdcan1, FDCAN_REJECT, FDCAN_REJECT, FDCAN_REJECT_REMOTE, FDCAN_REJECT_REMOTE);
    HAL_FDCAN_ConfigGlobalFilter(&hfdcan2, FDCAN_REJECT, FDCAN_REJECT, FDCAN_REJECT_REMOTE, FDCAN_REJECT_REMOTE);
}
